package com.project.service.impl;

import com.project.bean.UserBean;
import com.project.mapper.IUserMapper1;
import com.project.service.IUserService1;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class IUserService extends BaseService implements IUserService1 {
    @Override
    public UserBean login(String account, String pwd) {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        UserBean userBean=mapper.login(account,pwd);
        session.close();
        return userBean;
    }

    @Override
    public List<UserBean> findAllUser() {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        List<UserBean>list=mapper.findAllUser();
        session.close();
        return list;
    }

    @Override
    public boolean addUser(UserBean userBean) {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        mapper.addUser(userBean);
        session.commit();
        session.close();
        return false;
    }

    @Override
    public void deleteUser(int userId) {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        mapper.deleteUser(userId);
        session.commit();
        session.close();


    }

    @Override
    public void updateUser(int id, String garde) {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        mapper.updateUser(id,garde);
        session.commit();
        session.close();


    }

    @Override
    public UserBean findById(int id) {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        UserBean userBean=mapper.findById(id);
        session.close();
        return userBean;
    }

    @Override
    public void updatePwd(int id, String newPwd) {
        SqlSession session=this.getSession();
        IUserMapper1 mapper =session.getMapper(IUserMapper1.class);
        mapper.updatePwd(id,newPwd);
        session.commit();
        session.close();

    }
}
